package com.bdqn.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQConfig
 *
 * @author LILIBO
 * @since 2023-03-23
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 邮件消息交换机
     */
    public static final String EXCHANGE_NAME_EMAIL = "direct.cloud.email";

    /**
     * 邮件消息队列
     */
    public static final String QUEUE_NAME_EMAIL = "queue.cloud.email";

    /**
     * 邮件消息路由Key
     */
    public static final String ROUTING_KEY_EMAIL = "cloud.email";

    /**
     * 创建一个Email交换机
     */
    @Bean
    public DirectExchange directExchangeEmail() {
        return new DirectExchange(EXCHANGE_NAME_EMAIL);
    }

    /**
     * 创建一个Email队列
     */
    @Bean
    public Queue directQueueEmail() {
        return new Queue(QUEUE_NAME_EMAIL);
    }

    /**
     * 将Email队列绑定到交换机，并设置路由Key为“cloud.email”
     * @return
     */
    @Bean
    public Binding bindingEmail() {
        return BindingBuilder.bind(directQueueEmail()).to(directExchangeEmail()).with(ROUTING_KEY_EMAIL);
    }

}
